#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MESSAGE_LEN 110
#define MORSE_LEN   450

/*
A 	.- 	    H 	.... 	O 	--- 	V 	...-
B 	-... 	I 	.. 	    P 	.--. 	W 	.--
C 	-.-. 	J 	.--- 	Q 	--.- 	X 	-..-
D 	-.. 	K 	-.- 	R 	.-. 	Y 	-.--
E 	. 	    L 	.-.. 	S 	... 	Z 	--..
F 	..-. 	M 	-- 	    T 	- 	　 	　
G 	--. 	N 	-. 	    U 	..- 	　 	　

underscore 	..-- 	period 	        ---.
comma 	    .-.- 	question mark 	----
*/

char morsemap[][5] =
{   //a     b       c       d       e       f       g
    ".-",   "-...", "-.-.", "-..",  ".",    "..-.", "--.",
    //h     i       j       k       l       m       n
    "....", "..",   ".---", "-.-",  ".-..", "--",   "-.",
    //o     p       q       r       s       t       u
    "---",  ".--.", "--.-", ".-.",  "...",  "-",    "..-",
    //v     w       x       y       z
    "...-", ".--",  "-..-", "-.--", "--..",
    //_     .        ,       ?
    "..--", ".-.-", "---.", "----"
};

char charactermap[] =
{
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
    'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
    'Y', 'Z', '_', ',', '.', '?'
};

int N = 0;
int L = 0;
char message[MESSAGE_LEN] = "";
char morsestr[MORSE_LEN] = "";

int lenarray[MESSAGE_LEN] = {0};

void getmorse(char ch, char* morse)
{
    if(ch >= 'A' && ch <= 'Z')
    {
        strcpy(morse, morsemap[ch - 'A']);
    }
    else
    {
        if(ch == '_')
            strcpy(morse, morsemap[26]);
        else if(ch==',')
            strcpy(morse, morsemap[27]);
        else if(ch=='.')
            strcpy(morse, morsemap[28]);
        else if(ch=='?')
            strcpy(morse, morsemap[29]);
        else
            ;
    }
}

char getcharacter(char* str)
{
    int i = 0;

    for(i = 0; i < 30; i++)
    {
        if(strcmp(str, morsemap[i]) == 0)
        {
            return charactermap[i];
        }
    }
    return '!';
}

void swap(int* a, int* b)
{
    int temp = *a;
    *a = *b;
    *b = temp;
}

void reversearray()
{
    int i = 0;
    int k = L / 2;

    for(i = 0; i < k; i++)
    {
        swap(&lenarray[i], &lenarray[L - i - 1]);
    }
}

void translate()
{
    int i = 0, j = 0, k = 0, m = 0;
    char ch[6];

    for(i = 0; i < L; i++)
    {
        for(j = 0; j < lenarray[i]; j++)
        {
            ch[j] = morsestr[k++];
        }
        ch[j] = '\0';
        message[m++] = getcharacter(ch);
    }
    message[m] = '\0';

}

void init()
{
    L = 0;
    strcpy(message, "");
    strcpy(morsestr, "");
}

void process()
{
    int i = 0;
    char charmorse[5];

    for(i = 0; i < strlen(message); i++)
    {
        getmorse(message[i], charmorse);
        strcat(morsestr, charmorse);
        lenarray[L++] = strlen(charmorse);
    }
    reversearray();
    translate();
}

int main()
{
    int i = 0;
    //freopen("bin\\debug\\in.txt", "r", stdin);

    scanf("%d", &N);

    for(i = 0; i < N; i++)
    {
        init();
        scanf("%s", message);
        process();
        printf("%d: %s\r\n", i+1, message);
    }
    return 0;
}
